package cn.tradewin.advisor.pages.security;

import java.util.List;

import org.apache.tapestry5.EventConstants;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SetupRender;
import org.apache.tapestry5.beaneditor.BeanModel;
import org.apache.tapestry5.ioc.Messages;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.BeanModelSource;

import cn.tradewin.advisor.exceptions.DBException;
import cn.tradewin.advisor.persist.model.Roles;
import cn.tradewin.advisor.persist.services.AdvisorSecurityService;

public class RoleBoard {
	@Inject
	private Messages messages;
	
	@Inject
	private BeanModelSource beanModelSource;
	
	@Property
	private BeanModel<Roles> beanModel;
	
	@Inject
	private AdvisorSecurityService securityService;
	
	@Property
	private List<Roles> roles;
	
	@Property
	private Roles role;
	
	@SetupRender
	void setupRender() throws DBException {
		beanModel = beanModelSource.createDisplayModel(Roles.class, messages);
		beanModel.add("action", null);
		beanModel.include("roleId", "roleName", "roleDesc", "action");
		beanModel.get("roleId").sortable(false);
		beanModel.get("roleName").sortable(true);
		beanModel.get("roleDesc").sortable(false);
		beanModel.get("action").sortable(false);
	}	
	
	@OnEvent(EventConstants.PREPARE_FOR_RENDER)
	void prepareForRender() throws DBException {
		roles = securityService.listAllRoles();
	}
		
	public boolean isEmpty() {
		if (roles == null || roles.size() == 0)
			return true;
		return false;
	}
}
